package com.bryant.demo05.ui.home

import com.bryant.demo05.R
import com.bryant.demo05.bean.ChangeCityBean


import android.content.Context
import android.view.ViewGroup
import com.chad.library.adapter4.BaseQuickAdapter
import com.chad.library.adapter4.viewholder.QuickViewHolder


/**
 * 城市列表的adapter
 */
class CityListAdapter : BaseQuickAdapter<ChangeCityBean, QuickViewHolder>() {

    override fun onBindViewHolder(
        holder: QuickViewHolder,
        position: Int,
        item: ChangeCityBean?
    ) {
        holder.run {
            // 设置城市名称文本
            setText(R.id.tv_city_name, item?.cityName)

            // 判断是否为当前定位城市
            if (item?.isCurrentLocation == true) {
                // 隐藏定位图标
                setGone(R.id.iv_location, false)
                // 设置城市名称文字颜色为强调色
                setTextColor(R.id.tv_city_name, context.resources.getColor(R.color.colorAccent))
            } else {
                // 显示定位图标
                setGone(R.id.iv_location, true)
                // 设置城市名称文字颜色为白色
                setTextColor(R.id.tv_city_name, context.resources.getColor(R.color.white))
            }
        }
    }

    override fun onCreateViewHolder(
        context: Context,
        parent: ViewGroup,
        viewType: Int
    ): QuickViewHolder {
        return QuickViewHolder(R.layout.item_city_list, parent)
    }


}